package com.gitee.wsl.common.ui.ext

/*
import androidx.compose.ui.graphics.Path
import androidx.graphics.shapes.Cubic
import androidx.graphics.shapes.Morph
import androidx.graphics.shapes.MutableCubic
import androidx.graphics.shapes.TransformResult
import com.gitee.wsl.common.ui.base.Point
import com.gitee.wsl.common.ui.base.center
import com.gitee.wsl.common.ui.base.distance
import com.gitee.wsl.common.ui.base.percentAt
import com.gitee.wsl.common.ui.base.translate
import com.gitee.wsl.math.Math

*/
/**
 * Scales a shape (given as a Sequence) in place.
 * As this works in Sequences, it doesn't create the whole list at any point, only one
 * MutableCubic is (re)used.
 *//*

fun Sequence<MutableCubic>.scaled(scale: Float) = map {
    it.transform { x, y -> TransformResult(x * scale, y * scale) }
    it
}

*/
/**
 * Scales a shape (given as a List), creating a new List.
 *//*

fun List<Cubic>.scaled(scale: Float) = map {
    it.transformed { x, y -> TransformResult(x * scale, y * scale) }
}

 fun Cubic.anchor0() = Offset(anchor0X, anchor0Y)
 fun Cubic.control0() = Offset(control0X, control0Y)
 fun Cubic.control1() = Offset(control1X, control1Y)
 fun Cubic.anchor1() = Offset(anchor1X, anchor1Y)

*/
/**
 * Function used to create a Path from a list of Cubics.
 *//*

fun List<Cubic>.toPath(path: Path = Path()): Path {
    path.rewind()
    firstOrNull()?.let { first ->
        path.moveTo(first.anchor0X, first.anchor0Y)
    }
    for (bezier in this) {
        path.cubicTo(
            bezier.control0X, bezier.control0Y,
            bezier.control1X, bezier.control1Y,
            bezier.anchor1X, bezier.anchor1Y
        )
    }
    path.close()
    return path
}

*/
/**
 * Transforms the morph at a given progress into a [Path].
 * It can optionally be scaled, using the origin (0,0) as pivot point.
 *//*

fun Morph.toPath(progress: Float, scale: Float = 1f, path: Path = Path()): Path {
    var first = true
    path.rewind()
    forEachCubic(progress) { bezier ->
        if (first) {
            path.moveTo(bezier.anchor0X * scale, bezier.anchor0Y * scale)
            first = false
        }
        path.cubicTo(
            bezier.control0X * scale, bezier.control0Y * scale,
            bezier.control1X * scale, bezier.control1Y * scale,
            bezier.anchor1X * scale, bezier.anchor1Y * scale
        )
    }
    path.close()
    return path
}

// 求A点到B点的三次贝塞尔曲线的两个控制点
fun Math.curve3CtrlPoint(a: Point, b: Point, l: Point, n: Point):Pair<Point,Point> {
    // 点a前一个点和点a的中点
    val cLA: Point = l.center(a)
    // 点a和点b的中点
    val cAB: Point = a.center(b)
    // 点b和点b后一个点的中点
    val cBN: Point = b.center(n)

    // 点a前一个点到点a的距离
    val lenLA: Float = l.distance(a)
    // 点a到点b的距离
    val lenAB: Float = a.distance(b)
    // 点b到点b后一个点的距离
    val lenBN: Float = b.distance(n)

    // cLA和cAB连线的比例点
    val cLAB: Point = cLA.percentAt(cAB, lenLA / (lenLA + lenAB))
    val cABN: Point = cAB.percentAt( cBN, lenAB / (lenAB + lenBN))

    // 顶点a和顶点b的控制点1
    val aNode = cAB.translate( a.x - cLAB.x, a.y - cLAB.y)
    // 顶点a和顶点b的控制点2
    val bNode = cAB.translate( b.x - cABN.x, b.y - cABN.y)

    return aNode to bNode
}*/

